<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>网上请假系统</title>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
</head>
<body>

<div id="app">
    <div class="login">
        <!-- 左侧背景图片 -->
        <div class="login-left"></div>

        <!-- 右侧登录表单 -->
        <div class="login-right">
            <h1 id="loginMsg">网上请假系统</h1>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="账号" prop="userid">
                    <el-input type="text" v-model="ruleForm.userid" autocomplete="off" style="width: 100%" placeholder="请输入账号">
                        <template slot="prepend">
                            <i class="el-icon-user"></i>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="ruleForm.password" autocomplete="off" style="width: 100%" placeholder="请输入密码">
                        <template slot="prepend">
                            <i class="el-icon-lock"></i>
                        </template>
                    </el-input>
                </el-form-item>
                <el-form-item class="button-group">
                    <el-radio-group v-model="radio">
                        <el-radio :label=3>管理员</el-radio>
                        <el-radio :label=6>辅导员</el-radio>
                        <el-radio :label=9>学生</el-radio>
                    </el-radio-group>
                    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>

<script src="js/vue.js"></script>
<script src="js/axios-0.18.0.js"></script>
<script src="element-ui/lib/index.js"></script>

<script>
    new Vue({
        el: "#app",
        data() {
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入账号'));
                } else {
                    callback();
                }
            };
            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'));
                } else {
                    callback();
                }
            };
            return {
                radio: 3,
                ruleForm: {
                    userid: '',
                    password: '',
                },
                rules: {
                    userid: [
                        {validator: validatePass, trigger: 'blur'}//blur 输入框失去焦点时进行验证
                    ],
                    password: [
                        {validator: validatePass2, trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            submitForm(formName) {
                console.log(this.ruleForm)
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios.post('http://localhost:8080/user/login', this.ruleForm)
                            .then(result => {
                                console.log(result)
                                console.log(result.data)
                                console.log(result.data.msg)
                                if (result.data.msg == "success") {
                                    // 存储登录成功消息
                                    sessionStorage.setItem("loginMessage", '登录成功');
                                    location.href = `NavMenu.html?radio=${this.radio}`;

                                } else {
                                    this.$message.error(result.data.msg);
                                }
                            });
                    } else {
                        console.log('表单验证失败');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    })
</script>

<style lang="scss" scoped>
    body, html {
        margin: 0;
        padding: 0;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #f5f5f5; /* 背景色可调 */
        background: url("./imgs/login_bg.png") no-repeat center center;
    }

    .login {
        width: 800px; /* 登录框整体宽度 */
        height: 400px; /* 登录框整体高度 */
        display: flex;
        border-radius: 10px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        overflow: hidden; /* 防止内容溢出 */
        background-color: #fff;
    }

    .login img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .login-left {
        flex: 1; /* 左侧图片部分 */
        background: url('./imgs/Desert1.jpg') no-repeat center center;
        background-size: cover;
    }

    .login-right {
        flex: 1; /* 右侧表单部分 */
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 20px;
        box-sizing: border-box;
    }

    #loginMsg {
        text-align: center;
        font-size: 24px;
        color: #333;
        margin-bottom: 20px;
    }


    .button-group {
        display: flex;
        justify-content: space-between; /* 两端对齐 */
        gap: 10px; /* 按钮之间的间距 */
    }

    .button-group .el-button {
        flex: 1; /* 确保按钮宽度一致 */
    }
</style>


</body>
</html>
